import type { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
import axios from 'axios'

let baseURL = 'http://47.103.131.99:8085'

const axiosInstance: AxiosInstance = axios.create({
    baseURL,
    timeout: 1000 * 10,
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
    },
})

// 请求拦截器
axiosInstance.interceptors.request.use(
    (config: InternalAxiosRequestConfig) => {
        // config.headers.setAuthorization(`Bearer ${sessionStorage.getItem('token')}`)
        config.headers.setAuthorization(`Bearer tokenfkdjgndalj`)
        return config
    },
    (error: AxiosError) => {
        return Promise.reject(error)
    },
)

// 响应拦截器
axiosInstance.interceptors.response.use(
    (response: AxiosResponse) => {
    
      return response;
    },
    (error) => {
      // 处理响应错误
      return Promise.reject(error);
    }
  );


export default axiosInstance